package org.foreveross.que.infra.impl;

import java.util.List;

import org.apache.commons.lang3.StringUtils;
import org.foreveross.que.entity.MenuEntity;
import org.foreveross.que.infra.MenuRepository;
import org.foreveross.que.infra.base.ddd.repository.EntityHibernateRepository;
import org.springframework.stereotype.Repository;
@Repository
public class MenuRepositoryImpl extends EntityHibernateRepository implements MenuRepository {
	

//	@Resource(name="entityHibernateRepository")
//	IBaseRepository baseRepository;
	
	public List<MenuEntity> getMenus(String sysType){
		Object [] params = {sysType};
		List <MenuEntity> menus = this.queryResult("from MenuEntity t where t.state=1 and t.sysType = ?" ,params);
		return menus;
	}
	
	public MenuEntity findEntity(String mid){
		if(StringUtils.isBlank(mid)){
			return null;
		}
		if("0".equals(mid.trim())){
			return null;
		}
		List<MenuEntity> list = queryResult("from MenuEntity t where t.code=?",new Object[]{mid});
		if(list==null||list.size()==0){
			return null;
		}
		return list.get(0);
	}
	
	public List<MenuEntity> findByPid(String pid) throws Exception{
		String sql = "from MenuEntity t where t.pid = ?";
		return this.queryResult(sql, new Object[]{pid});
	}

}
